Imports System.Data
Imports Microsoft.Win32

Public Class gestTS
    Inherits System.Web.UI.Page

    'Protected WithEvents lkSalva As System.Web.UI.WebControls.LinkButton
    'Protected WithEvents lkAnnulla As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Dataset11 As Dataset2
    Protected WithEvents da As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    'Protected WithEvents opName As System.Web.UI.HtmlControls.HtmlInputHidden
    'Protected WithEvents dTipo As System.Web.UI.WebControls.DropDownList

    Dim ParentTable As String = "TitoloDiStudioSpecializzazione"

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataSet11 = New Dataset2
        Me.da = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'DataSet11
        '
        Me.DataSet11.DataSetName = "DataSet1"
        Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'da
        '
        Me.da.InsertCommand = Me.SqlInsertCommand1
        Me.da.SelectCommand = Me.SqlSelectCommand1
        Me.da.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", Session("nomeTab"), New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("codice", "codice"), New System.Data.Common.DataColumnMapping("tipo_ts", "tipo_ts"), New System.Data.Common.DataColumnMapping("descrizione", "descrizione")})})
        Me.da.UpdateCommand = Me.SqlUpdateCommand1
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT codice, tipo_ts, descrizione FROM TitoloDiStudioSpecializzazione"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO TitoloDiStudioSpecializzazione (tipo_ts, descrizione) VALUES (@tipo, @descrizione); SELECT codice, tipo_ts, descr" & _
        "izione FROM TitoloDiStudioSpecializzazione WHERE (codice = @@IDENTITY)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@tipo", System.Data.SqlDbType.SmallInt, 2, "tipo_ts"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE TitoloDiStudioSpecializzazione  SET tipo_ts=@tipo, descrizione = @descrizione WHERE (codice = @Original_codi" & _
        "ce) AND (descrizione = @Original_descrizione OR @Original_descrizione IS NULL AN" & _
        "D descrizione IS NULL); SELECT codice, tipo_ts, descrizione FROM TitoloDiStudioSpecializzazione  WHERE (codi" & _
        "ce = @codice)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@descrizione", System.Data.SqlDbType.VarChar, 50, "descrizione"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@tipo", System.Data.SqlDbType.SmallInt, 2, "tipo_ts"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_codice", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "codice", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_descrizione", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "descrizione", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@codice", System.Data.SqlDbType.SmallInt, 2, "codice"))
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings("ConnString")

        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents UcTestata1 As ucTestata

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        populateDataSet()
        If (Not Me.IsPostBack) Then
           
            If New cConfigura(False).conf.laurea Then
                dTipo.DataSource = (New Connessione).getDataTable("select * from tipoTitoloDiStudio")
            Else
                dTipo.DataSource = (New Connessione).getDataTable("select * from tipoTitoloDiStudio where codice <3")
            End If
            dTipo.DataBind()
            dTipo.SelectedIndex = 0

            populateDataSet()


        End If
        'Put user code to initialize the page here
    End Sub

    Private Sub populateDataSet()
        If dTipo.SelectedValue <> "" Then
            da.SelectCommand.CommandText = "SELECT codice, tipo_ts, descrizione FROM TitoloDiStudioSpecializzazione where tipo_ts=" & dTipo.SelectedValue

            da.Fill(Dataset11, ParentTable)
        End If

    End Sub



    Private Sub lkSalva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkSalva.Click
        Try

            'Call update on the adapter to commit the changes, catch any exceptions that may be raised.
            da.Update(Dataset11.Tables(ParentTable))

        Catch
            Dataset11.RejectChanges()
        End Try
    End Sub

    Private Sub lkAnnulla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkAnnulla.Click
        Dataset11.RejectChanges()

    End Sub


    Private Sub dTipo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dTipo.SelectedIndexChanged
        populateDataSet()

    End Sub
End Class

